Energy Consumption Analysis¶

In [3]:
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('ggplot')
In [4]:
df = pd.read_csv('14. Ground Floor vs InsideTemperature.csv')
In [5]:
df.head()
Out[5]:
Date InsideTemperature GroundFloor Unnamed: 3 Unnamed: 4
0 6/16/2021 0:00 27.430000 3.389676 NaN NaN
1 6/17/2021 0:00 28.200000 6.925224 NaN NaN
2 6/18/2021 0:00 29.063333 6.934230 NaN NaN
3 6/19/2021 0:00 29.127500 6.912297 NaN NaN
4 6/20/2021 0:00 29.230833 6.904380 NaN NaN
In [6]:
df.dtypes
Out[6]:
Date                  object
InsideTemperature    float64
GroundFloor          float64
Unnamed: 3           float64
Unnamed: 4            object
dtype: object
In [7]:
df['Date'] =  pd.to_datetime(df['Date'])
In [8]:
df.head()
Out[8]:
Date InsideTemperature GroundFloor Unnamed: 3 Unnamed: 4
0 2021-06-16 27.430000 3.389676 NaN NaN
1 2021-06-17 28.200000 6.925224 NaN NaN
2 2021-06-18 29.063333 6.934230 NaN NaN
3 2021-06-19 29.127500 6.912297 NaN NaN
4 2021-06-20 29.230833 6.904380 NaN NaN
In [9]:
df['month'] = df['Date'].dt.month
In [10]:
df.head()
Out[10]:
Date InsideTemperature GroundFloor Unnamed: 3 Unnamed: 4 month
0 2021-06-16 27.430000 3.389676 NaN NaN 6
1 2021-06-17 28.200000 6.925224 NaN NaN 6
2 2021-06-18 29.063333 6.934230 NaN NaN 6
3 2021-06-19 29.127500 6.912297 NaN NaN 6
4 2021-06-20 29.230833 6.904380 NaN NaN 6
In [11]:
df['week'] = df.Date.dt.strftime('%W')
In [12]:
df1 = df.groupby('month',as_index=False).mean()
In [13]:
df2 = df.groupby('week',as_index=False).mean()
In [14]:
fig, ax = plt.subplots(figsize=(20,10))
ax2 = ax.twinx()
ax.set_title('Avg Monthly Temperature and Energy Consumption', fontsize = 20)
ax.set_xlabel('Month')
ax.plot(df1['month'], df1['InsideTemperature'], color='green', marker='x')
ax2.plot(df1['month'], df1['GroundFloor'], color='red', marker='o')
ax.set_ylabel('Inside Temperature [°C]')
ax2.set_ylabel('Thermal energy for heating & cooling [kwh]')
ax.legend(['Inside Temperature [°C]'], loc='upper left')
ax2.legend(['Thermal energy for heating & cooling [kwh]'], loc='upper right')
#ax.set_xticks(df['Date'].dt.date)
#ax.set_xticklabels(df['Date'].dt.year, rotation=90)
plt.show()
In [17]:
fig, ax = plt.subplots(figsize=(20,10) )
plt.rcParams['figure.dpi'] = 2000
ax2 = ax.twinx()
ax.set_title('Avg Weekly Temperature and Energy Consumption', fontsize = 20)
ax.set_xlabel('Week')
ax.plot(df2['week'], df2['InsideTemperature'], color='green', marker='x')
df2.plot(x='week', y='GroundFloor', kind='bar', ax=ax, alpha=0.4, color='red')
ax.set_ylabel('Inside Temperature [°C]', fontsize = 10)
ax2.set_ylabel('Thermal energy for heating & cooling [kwh]',fontsize = 10)
ax.legend(['Inside Temperature [°C]'], loc='upper left',fontsize = 10)
plt.show()
In [ ]: